home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-11 | 4.0 KB | 193 lines | [TEXT/MMCC] |
- // LifeModules.c
- // Handle the Life Implementation Modules for Mike's Life.
- // Copyright ©1995 Michael D. Crawford. All Rights Reserved.
- // 23 Jun 95 Mike Crawford crawford@scruznet.com
- //
- // Revision History:
- // 23 Jun 95 MDC New today
- //
- // The Atrium in Southfield, Michigan is a pretty good place to eat at
- // four in the morning. It has those little jukeboxes at each table
- // so you can play bad music to annoy the other diners.
- //
- // Don't get the Greek Salad. It sucks.
- //
- // Get the CD of the band "Yellow". It is very good.
-
- #include <QDOffscreen.h>
- #include "Control.h"
- #include "LifeModules.h"
- #include "StupidWay.h"
-
- #define kProcMenuID 200
-
- OSErr CountPlugIns( short *numPtr );
- void MyAppendMenu( MenuHandle mHdl, StringPtr item );
-
- short gNumModules;
- tLifeProcsPtr gLifeProcs;
-
- OSErr InitModules( void )
- {
- short numPlugIns;
- short numBuiltIns;
- MenuHandle procMenu;
- OSErr err;
-
- procMenu = GetMenu( kProcMenuID ); // This allocates an empty module menu
- if ( !procMenu )
- return resNotFound;
-
- err = CountPlugIns( &numPlugIns );
- if ( err )
- return err;
-
- #define kNumBuiltIns 1
- numBuiltIns = kNumBuiltIns;
-
- gNumModules = numBuiltIns + numPlugIns;
-
- // We don't want to use handles on PowerPC, because it
- // blows a cache line to dereference a handle. :’-<
-
- gLifeProcs = (tLifeProcsPtr)NewPtr( sizeof(tLifeProcRecord) * gNumModules );
- if ( !gLifeProcs )
- return memFullErr;
-
- // Add in the built-ins first
-
- err = AddStupidWay( &gLifeProcs[ 0 ] );
-
- return noErr;
- }
-
- OSErr AddLifeProcs( tLifeProcsPtr lifeProcPtr,
- short procType,
- StringPtr menuStr,
- tStepProc stepProc,
- tLifeAllocProc allocProc,
- tClearRectProc clearPixProc,
- tFreeProc freeProc,
- tToggleCellProc toggleProc,
- tDrawCellProc drawCellProc,
- tDrawWinProc drawProc,
- FSSpecPtr specPtr )
- {
- MenuHandle procMenu;
-
- // Fill in a life proc record
-
- lifeProcPtr->procType = procType;
-
- lifeProcPtr->stepProc = stepProc;
- lifeProcPtr->allocProc = allocProc;
- lifeProcPtr->clearPixProc = clearPixProc;
- lifeProcPtr->freeProc = freeProc;
- lifeProcPtr->toggleProc = toggleProc;
- lifeProcPtr->drawCellProc = drawCellProc;
- lifeProcPtr->drawProc = drawProc;
- lifeProcPtr->fileSpec.vRefNum = specPtr->vRefNum;
- lifeProcPtr->fileSpec.parID = specPtr->parID;
-
- BlockMove( &( specPtr->name[ 0 ] ),
- &( lifeProcPtr->fileSpec.name[ 0 ] ),
- specPtr->name[ 0 ] + 1 );
-
- #ifdef MAYBE_SOMEDAY
- switch( procType ){ // Do type-specific initialization
- case kBuiltIn:
- break;
- case k68kCodeResource:
- break;
- case kPPCCodeFrag:
- break;
- }
- #endif
-
- procMenu = GetMHandle( kProcMenuID );
- if ( !procMenu )
- return resNotFound;
-
- MyAppendMenu( procMenu, menuStr );
-
- return noErr;
- }
-
- void MyAppendMenu( MenuHandle mHdl, StringPtr itemStr )
- {
- // STUB Fix this so special chars aren't interpreted
-
- AppendMenu( mHdl, itemStr );
-
- return;
- }
-
- OSErr CountPlugIns( short *numPtr )
- {
- *numPtr = 0;
-
- return noErr;
- }
-
- OSErr AllocLifeWorld( tLifeWorldPtr worldPtr, long height, long width )
- {
- tLifeProcsPtr lifeProcPtr;
- OSErr err;
-
-
- lifeProcPtr = (tLifeProcsPtr)( worldPtr->lifeModuleProcs );
-
- err = (*(lifeProcPtr->allocProc))( worldPtr, height, width );
-
- return err;
- }
-
- OSErr LifeStep( tLifeWorldPtr worldPtr )
- {
- tLifeProcsPtr lifeProcPtr;
- OSErr err;
-
- lifeProcPtr = (tLifeProcsPtr)( worldPtr->lifeModuleProcs );
-
- err = (*(lifeProcPtr->stepProc))( worldPtr );
-
- return err;
- }
-
- OSErr ClearCells( tLifeWorldPtr worldPtr, tLongRect *rPtr )
- {
- tLifeProcsPtr lifeProcPtr;
- OSErr err;
-
- lifeProcPtr = (tLifeProcsPtr)( worldPtr->lifeModuleProcs );
-
- err = (*(lifeProcPtr->clearPixProc))( worldPtr, rPtr );
-
- return err;
- }
-
- OSErr DrawLifeWorld( tLifeWorldPtr worldPtr )
- {
- tLifeProcsPtr lifeProcPtr;
- OSErr err;
-
- lifeProcPtr = (tLifeProcsPtr)( worldPtr->lifeModuleProcs );
-
- err = (*(lifeProcPtr->drawProc))( worldPtr );
-
- return err;
- }
-
-
- void *GetModuleProcs( short moduleNumber )
- {
- tLifeProcsPtr lifeProcPtr;
-
- // assert( ( moduleNumber >= 0 && moduleNumber < gNumModules ) );
-
- lifeProcPtr = &( gLifeProcs[ moduleNumber ] );
-
- return lifeProcPtr;
- }
-
-